<?php
namespace app\api\controller;

use app\api\logic\AfterSaleLogic;

/**
 * 售后
 * Class Order
 * @package app\api\controller
 */
class AfterSaleController extends ApiBase
{
    public function lists()
    {
        $user_id =$this->uid??0;
        if(!$user_id){
            return unauthorized('请先授权');
        }
        $type = $this->request->get('type', 'normal');
        $lists = AfterSaleLogic::lists($user_id, $type,$this->page,$this->limit);
        return success($lists);
    }


    public function add()
    {
        $post = $this->request->post();
        $user_id =$this->uid??0;
        if(!$user_id){
            return unauthorized('请先授权');
        }
        $post['user_id'] = $user_id;
        $check = $this->validate($post, 'app\api\validate\AfterSale.add');
        if (true !== $check) {
            return error($check);
        }
        return AfterSaleLogic::add($post, $user_id);
    }


    //售后商品信息
    public function goodsInfo()
    {
        $get = $this->request->get();
        $check = $this->validate($get, 'app\api\validate\AfterSale.info');
        if (true !== $check) {
            return error($check);
        }
        return success(AfterSaleLogic::info($get['item_id'], $get['order_id']));
    }


    public function express()
    {
        $user_id =$this->uid??0;
        if(!$user_id){
            return unauthorized('请先授权');
        }
        $post = $this->request->post();
        $check = $this->validate($post, 'app\api\validate\AfterSale.express');
        if (true !== $check) {
            return error($check);
        }
        return AfterSaleLogic::express($user_id, $post);
    }


    public function cancel()
    {
        $user_id =$this->uid??0;
        if(!$user_id){
            return unauthorized('请先授权');
        }
        $post = $this->request->post();
        $check = $this->validate($post, 'app\api\validate\AfterSale.cancel');
        if (true !== $check) {
            return error($check);
        }
        AfterSaleLogic::cancel($user_id, $post);
        return success('撤销成功');
    }


    
    public function detail()
    {
        $get = $this->request->get();
        $info=AfterSaleLogic::detail($get);
        return success($info);
    }



    public function again()
    {
        $user_id =$this->uid??0;
        if(!$user_id){
            return unauthorized('请先授权');
        }
        $post = $this->request->post();
        $check = $this->validate($post, 'app\api\validate\AfterSale.again');
        if (true !== $check) {
            return error($check);
        }
        return AfterSaleLogic::again($user_id, $post);
    }
}